package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.Datacenter;
import com.accelstack.cmp.repository.DatacenterRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * 数据中心Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class DatacenterService {
    
    private final DatacenterRepository datacenterRepository;
    
    @Transactional
    public Datacenter create(Datacenter datacenter) {
        return datacenterRepository.save(datacenter);
    }
    
    @Transactional
    public Datacenter update(Datacenter datacenter) {
        return datacenterRepository.save(datacenter);
    }
    
    @Transactional
    public void deleteById(Long id) {
        datacenterRepository.deleteById(id);
    }
    
    public Optional<Datacenter> findById(Long id) {
        return datacenterRepository.findById(id);
    }
    
    public List<Datacenter> findAll() {
        return datacenterRepository.findAll();
    }
    
    public Page<Datacenter> findAll(Pageable pageable) {
        return datacenterRepository.findAll(pageable);
    }
}

